<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="${initParam.url }/statics/css/detail.css" rel="stylesheet">
<link href="${initParam.url }/statics/css/compilewrite.css"
	rel="stylesheet">
<script src="${initParam.url}/statics/js/jquery-1.12.4.js"></script>
<script>
	$(document).ready(function() {

		$("#password2").blur(checkpassword);
		$("#password").blur(checkPass);
		$("#phone").blur(checkPhone);
		$("#name").blur(checkUsername);

		$("#btn").click(function() {
			var flag = true;
			if (!checkpassword()) {
				flag = false;
			}
			if (!checkPass()) {
				flag = false;
			}
			if (!checkUsername()) {
				flag = false;
			}
			if (!checkPhone()) {
				flag = false;
			}
			if (flag == true) {

				$("#jo").submit();
			}
		})
	})
	//验证密码
	function checkPass() {
		var $pwd = $("#password");
		var $divID = $("#DivPassword");
		$divID.html("");
		if ($pwd.val() == "") {
			$divID.html("密码不能为空");
			return false;
		}
		return true;
	}
	
	//验证密码
	function checkPhone() {
		var $phone = $("#phone");
		var $divID = $("#DivPhone");
		$divID.html("");
		if ($phone.val() == "") {
			$divID.html("手机号码不能为空");
			return false;
		}
		if ($phone.val().length != 11) {
			$divID.html("请输入正确的手机号码");
			return false;
		}	
		return true;
	}

	function checkpassword() {
		var $pwd = $("#password");
		var $repwd = $("#password2");
		var $divID = $("#DivPassword2");
		$divID.html("");
		if ($pwd.val() != $repwd.val()) {
			$divID.html("两次输入的密码不一致");
			return false;
		}
		return true;
	}
	//验证名字
	function checkUsername() {
		var $fname = $("#name");
		var $divID = $("#DivUsername");
		$divID.html("");
		if ($fname.val() == "") {
			$divID.html("用户名不能为空");
			return false;
		}
			$.ajaxSettings.async = false;
			$.get("/property/check", {
				username : $("#name").val()
			}, function(data) {
				if (data > 0) {
					$("#DivUsername").text("用户名存在");
				} else {
					$("#DivUsername").text("");
				}
			})
			$.ajaxSettings.async = true;
			if ($("#DivUsername").text() != null
					&& $("#DivUsername").text() != "") {
				return false;
			}
		return true;
	}
</script>
</head>

<body>
	<div
		style="width: 1090px; height: 490px; background-color: #FFF; margin: 20px;">
		<h4
			style="background-color: #9FB2C2; padding-left: 10px; color: #516D8A; line-height: 40px;">
			<img alt="" src="${initParam.url}/statics/images/title.jpg">
			添加平台管理员信息
		</h4>

		<div class="sp">
			<form action="addmanage" method="post" id="jo">

				<br /> <span style="color: red;">${error }</span>
				<table>
					<tr>
						<td class="tr-1">所属小区:</td>
						<td width="500px">
							<select id="communityid" name="communityid">	
            					<c:forEach var="communities" items="${communities}">
            						<option value="${communities.id}">${communities.communityName}</option>
            					</c:forEach>        			   		   
							</select>
						</td>
					<tr>
					<tr>
						<td class="tr-1">用户名:</td>
						<td width="500px"><input class="tr-2 form-control"
							style="width: 220px; height: 25px; display: inline;" name="name"
							id="name" type="text" />&nbsp;<span id='DivUsername'></span></td>
					<tr>
						<td class="tr-1">密码:</td>
						<td><input class="tr-2 form-control"
							style="width: 220px; height: 25px; display: inline;"
							name="password" id="password" type="password" />&nbsp;<span
							id='DivPassword'></span></td>
					</tr>
					<tr>
						<td class="tr-1">确认密码:</td>
						<td><input class="tr-2 form-control"
							style="width: 220px; height: 25px; display: inline;"
							name="password2" id="password2" type="password" />&nbsp;<span
							id='DivPassword2'></span></td>
					</tr>
					<tr>
						<td class="tr-1">手机号码:</td>
						<td><input class="tr-2 form-control"
							style="width: 220px; height: 25px; display: inline;"
							name="phone" id="phone" type="text" />&nbsp;<span
							id='DivPhone'></span></td>
					</tr>
					<tr>
						<td class="tr-1">邮箱地址:</td>
						<td><input class="tr-2 form-control"
							style="width: 220px; height: 25px; display: inline;" name="email"
							id="email" type="text" required /></td>
					</tr>
					<tr>
						<td colspan="2" class="td-1"><input type="button"
							class="btn btn-default" value="确定" id="btn"> <input
							type="button" class="btn btn-default"
							onclick="history.go(-1)"
							value="取消"></td>
					</tr>
				</table>

			</form>

		</div>
	</div>
</body>
</html>